﻿using TransformTool.Transformers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;

namespace TestProjectTransformtool
{
    
    
    /// <summary>
    ///This is a test class for CRC32TransformerTest and is intended
    ///to contain all CRC32TransformerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CRC32TransformerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DoTransform
        ///</summary>
        [TestMethod()]
        [DeploymentItem("TransformTool.exe")]
        public void DoTransformTest()
        {
            //Arrange
            var crc32 = new CRC32Transformer();
            var referenceBytes = Encoding.UTF8.GetBytes("123456789");

            CRC32Transformer_Accessor target = new CRC32Transformer_Accessor(); 
            UInt32 crcReference = 0xCBF43926;
            
            var expectedBytes = BitConverter.GetBytes(crcReference);
            //If the system is little endian, we need to reverse the bytes. 
            if (BitConverter.IsLittleEndian)
                Array.Reverse(expectedBytes);

            //Act

            var actual = (byte[]) target.DoTransform(referenceBytes);
            
            //Assert
            Assert.AreEqual(expectedBytes.Length, actual.Length);
            for (int i = 0; i < expectedBytes.Length; i++)
                Assert.AreEqual(expectedBytes[i], actual[i]);
        }
    }
}
